package com.colorful.insuranceproject.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.colorful.insuranceproject.R;
import com.colorful.insuranceproject.bean.AboutClaimsProgressBean;
import com.colorful.insuranceproject.consts.ClaimsStatus;
import com.lovely3x.common.adapter.BaseViewHolder;
import com.lovely3x.common.adapter.ListAdapter;
import com.lovely3x.imageloader.ImageLoader;

import java.util.List;

import butterknife.Bind;

/**
 * Created by handsome-Bob on 2017/8/18.
 * <p>
 * 理赔进度的适配器
 */
public class ClaimsProgressAdapter extends ListAdapter<AboutClaimsProgressBean> {

    public ClaimsProgressAdapter(List<AboutClaimsProgressBean> datas, Context context) {
        super(datas, context);
    }

    @NonNull
    @Override
    public BaseViewHolder createViewHolder(int position, ViewGroup parent) {
        return new ViewHolder(getLayoutInflater().inflate(R.layout.item_claims_progress, parent, false));
    }

    @Override
    public void handleData(final int position, @NonNull BaseViewHolder holder) {
        ViewHolder viewHolder = (ViewHolder) holder;
        AboutClaimsProgressBean bean = datas.get(position);

        viewHolder.tvOrderNum.setText(bean.getInsuranceNo());//  理赔单号
        viewHolder.tvClaimsMoney.setText(bean.getInsuranceMoney());//  理赔金额
        viewHolder.tvClaimsStatus.setText(ClaimsStatus.judgeCaimsSatus(bean.getInsuranceStatus()));//  理赔状态
        viewHolder.tvClaimsTime.setText(bean.getInsuranceTime());//  理赔时间

        final View.OnClickListener onClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mViewClickedListener != null){
                    mViewClickedListener.onViewClicked(position,v);
                }
            }
        };

        viewHolder.tvOrderNum.setOnClickListener(onClickListener);
        viewHolder.viewLine.setVisibility(position == getCount() - 1 ? View.GONE : View.VISIBLE);
    }

    class ViewHolder extends BaseViewHolder {


        @Bind(R.id.tv_order_num)
        TextView tvOrderNum;

        @Bind(R.id.tv_claims_money)
        TextView tvClaimsMoney;

        @Bind(R.id.tv_claims_status)
        TextView tvClaimsStatus;

        @Bind(R.id.tv_claims_time)
        TextView tvClaimsTime;

        @Bind(R.id.view_line)
        View viewLine;

        public ViewHolder(View rootView) {
            super(rootView);
        }
    }
}
